@extends('system.frame_layout')
<?php $parent_menu = "购物商城"; $menu_selected = "我的收货地址";?>

@section('content')
    <div id="content-panel">
        <div class="row">
            <div class="col-xs-12">
                <div class="portlet light bordered">
                    <div class="portlet-title">
                        <div class="caption">
                            <i class="icon-social-dribbble font-dark hide"></i>
                            <span class="caption-subject font-dark bold">我的收货地址 My Address</span>
                        </div>
                    </div>
                    <div class="portlet-body">
                        <div class="form-group">
                            <form id="address" action="{{route('sys.address.save')}}" method="post">
                                {{csrf_field()}}

                                <div class="form-body">

                                    <div class="row input-row">
                                        <label class="col-xs-12 title" for="exampleInputPassword1">
                                            收货人姓名 - Name
                                        </label>
                                        <div class="col-md-4 col-xs-12">
                                            <div class="input-group">
                                                    <span class="input-group-addon">
                                                        <i class="iconfont icon-bixuan-copy font-red"></i>
                                                    </span>
                                                <input id="name" name="name" type="text" class="form-control"
                                                       placeholder="请输入您的收货人姓名" value="{{$addr->name or ""}}">
                                            </div>
                                        </div>
                                        <div class="col-xs-12 col-md-6">
                                            <label class="label-intro"></label>
                                        </div>
                                    </div>

                                    <div class="row input-row">
                                        <label class="col-xs-12 title" for="exampleInputPassword1">
                                            联系方式 - Telephone Number
                                        </label>
                                        <div class="col-md-4 col-xs-12">
                                            <div class="input-group">
                                                    <span class="input-group-addon">
                                                        <i class="iconfont icon-bixuan-copy font-red"></i>
                                                    </span>
                                                <input id="tel" name="tel" type="text" class="form-control"
                                                       placeholder="请输入您的手机号" value="{{$addr->tel or ""}}">
                                            </div>
                                        </div>
                                        <div class="col-xs-12 col-md-6">
                                            <label class="label-intro"></label>
                                        </div>
                                    </div>

                                    <?php $attr = user_attr(\App\Models\MUserAttr::$ACCEPT_ADDR_ATTR)?>
                                    @if(!empty($attr))
                                        @foreach($attr as $k=>$v)
                                            <input type="hidden" value="{{$v->rule}}" name="rule[]">
                                            <input type="hidden" value="{{$v->msg}}" name="msg[]">
                                            <div class="row input-row">
                                                <label class="col-xs-12 title" for="exampleInputPassword1">
                                                    {{$v->name}}
                                                </label>
                                                <div class="col-md-4 col-xs-12">
                                                    <div class="input-group">
                                                    <span class="input-group-addon">
                                                        <i class="iconfont icon-bixuan-copy font-red"></i>
                                                    </span>
                                                        <input id="tel" name="{{$v->mark}}" type="text" class="form-control"
                                                               placeholder="">
                                                    </div>
                                                </div>
                                                <div class="col-xs-12 col-md-6">
                                                    <label class="label-intro"></label>
                                                </div>
                                            </div>
                                        @endforeach
                                    @endif

                                    <div class="row input-row">
                                        <label class="col-xs-12 title" for="exampleInputPassword1">
                                            省-市-区（县） - Province-City-Area
                                        </label>
                                        <div class="col-md-4 col-xs-12">
                                            <div class="input-group">
                                                    <span class="input-group-addon">
                                                        <i class="iconfont icon-bixuan-copy font-red"></i>
                                                    </span>
                                                <input id="city" name="city" type="text" class="form-control"
                                                       placeholder="河南省-郑州市-金水区" value="{{$addr->city or ""}}">
                                            </div>
                                        </div>
                                        <div class="col-xs-12 col-md-6">
                                            <label class="label-intro"></label>
                                        </div>
                                    </div>

                                    <div class="row input-row">
                                        <label class="col-xs-12 title" for="exampleInputPassword1">
                                            街道详细地址 - Street Address
                                        </label>
                                        <div class="col-md-4 col-xs-12">
                                            <div class="input-group">
                                                    <span class="input-group-addon">
                                                        <i class="iconfont icon-bixuan-copy font-red"></i>
                                                    </span>
                                                <input id="detail" name="detail" type="text" class="form-control"
                                                       placeholder="平安街黄河小区3单元001号" value="{{$addr->detail or ""}}">
                                            </div>
                                        </div>
                                        <div class="col-xs-12 col-md-6">
                                            <label class="label-intro"></label>
                                        </div>
                                    </div>

                                    <div class="row input-row">
                                        <div class="col-xs-12">
                                            <button type="submit" class="btn blue-madison">
                                                <i class="iconfont icon-duihao"></i>&nbsp;立即保存
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('footer')
    <script type="text/javascript">
        $("#address").validate({
            rules: {
                name: {
                    required: true,
                    minlength: 2,
                    maxlength: 10
                },
                tel: {
                    required: true,
                    maxlength: 20
                },
                city: {
                    required: true,
                    maxlength: 255
                },
                detail: {
                    required: true,
                    maxlength: 255
                }
            }, errorPlacement: function (error, element) {
                $(element).closest(".input-row").find(".label-intro").html(error);
            },
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        if (data.code == 0) {
                            toastr["success"](data.msg);
                            setInterval(function () {
                                window.location.reload();
                            }, 2000);
                        } else {
                            toastr["error"](data.msg);
                        }
                    }
                });
            }
        });
    </script>
@endsection